#!/bin/bash
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

HOSTNAME=$1
LANA=${HOSTNAME}1
LANB=${HOSTNAME}2

exec 2>/dev/null

if cat </dev/tcp/"$LANA"/6556; then
    echo '<<<local:sep(0)>>>'
    echo "0 LAN-A - OK - Rechner via LAN-A erreichbar"
    if /usr/lib/nagios/plugins/check_icmp "$LANB" >/dev/null 2>&1; then
        echo "0 LAN-B - OK - Rechner via LAN-B erreichbar"
    else
        echo "2 LAN-B - CRIT - Rechner via LAN-B nicht erreichbar"
    fi
else
    if cat </dev/tcp/"$LANB"/6556; then
        echo '<<<local:sep(0)>>>'
        echo "2 LAN-A - CRIT - Rechner via LAN-A nicht erreichbar"
        echo "0 LAN-B - OK - Rechner via LAN-B erreichbar"
    else
        echo '<<<local:sep(0)>>>'
        echo "2 LAN-A - CRIT - Rechner via LAN-A nicht erreichbar"
        echo "2 LAN-B - CRIT - Rechner via LAN-B nicht erreichbar"
        exit 1 # Beide LANs erfolglos
    fi
fi
